<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Ar_zones extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('upload');
		$this->load->library('variable');
	}

	public function index() {
		$this->load->view('layouts/header', $this->variable->load_data($this->session->userdata('title')));
		$this->load->view($this->session->userdata('formain'),array('zones' => $this->ar_zones_model->get_zones()));
		$this->load->view('layouts/footer');
	}

	public function add_form() {
		$this->load->view($this->session->userdata('foradd'),array('zones' => $this->ar_zones_model->get_zones()));
	}

	public function edit_form($id) {
		$this->load->view($this->session->userdata('foredit'));
	}

	public function view_form($id) {
		$this->load->view($this->session->userdata('forview'));
	}

	public function getzone(){
		echo json_encode($this->ar_zones_model->getzone($this->input->post('zonecode')));
	}

	public function getzoneval(){
		echo json_encode($this->ar_zones_model->getzoneval($this->input->post('zonecode')));
	}

	public function getzonechild(){
		echo json_encode($this->ar_zones_model->getzonechild($this->input->post('parentid')));
	}

	public function savezones(){
		$data = array(
			    $this->input->post('zonecode'),
				$this->input->post('value_name'),
				$this->input->post('description'),
				(empty($this->input->post('enable_flag')) ? 'N' : 'Y'),
				$this->input->post('parent_id'),
				$this->session->userdata('user_id'),
			);
		echo json_encode($this->ar_zones_model->savezones($data));
	}

	public function savechild(){
		$data = array(
			    $this->input->post('zonecode'),
				$this->input->post('value_name'),
				$this->input->post('description'),
				(empty($this->input->post('enable_flag')) ? 'N' : 'Y'),
				$this->input->post('parentid'),
				$this->session->userdata('user_id'),
			);
		echo json_encode($this->ar_zones_model->savezones($data));
	}

	public function save(){
		$data = array(
				$this->input->post('fieldlabel32'),
				$this->input->post('zonecode32'),
				(empty($this->input->post('enable_flag')) ? 'N' : 'Y'),
				$this->session->userdata('user_id')
			);
		echo json_encode($this->ar_zones_model->save($data));
		//echo json_encode(($data));
	}

	public function editchild(){
		$data = array(
				$this->input->post('val_id'),
				$this->input->post('value_name'),
				$this->input->post('description'),
				(empty($this->input->post('enable_flag')) ? 'N' : 'Y'),
				$this->session->userdata('user_id')
			);
		echo json_encode($this->ar_zones_model->editchild($data));
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */